package com.atguigu.bigdata.spark.core.rdd.operator.action;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaSparkContext;
import scala.Tuple2;

import java.util.Arrays;
import java.util.List;

public class Spark05_RDD_Operator_Action_JAVA {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setMaster("local[*]").setAppName("sparkCore");
        JavaSparkContext sc = new JavaSparkContext(conf);

        List<Tuple2<String, Integer>> list = Arrays.asList(new Tuple2<String,Integer>("a", 1),
                new Tuple2<String,Integer>("a",2), new Tuple2<String, Integer>("b", 1),
                new Tuple2<String, Integer>("b", 1));

        // saveAsSequenceFile方法要求数据的格式必须为K-V类型

        JavaPairRDD<String,Integer> pairRdd = sc.parallelizePairs(list, 2);
        pairRdd.saveAsTextFile("output");
        pairRdd.saveAsObjectFile("output");

    }
}
